#include "widget.h"

#include <QApplication>
#include "dht11.h"
#include <QFile>
#include "cliect.h"
#include "config.h"
#include "usart.h"
#include "light_test.h"
#include <iostream>
#include <thread>

void copy(QString file)
{
    if(!QFile::exists(file))
    {
        QFile f(":/res/" + file);
        f.copy(file);
    }
}

int main(int argc, char *argv[])
{
    copy("light_drv.ko");
    copy("temp_dev.ko");
    copy("led_drv.ko");
    copy("beep_drv.ko");
    copy("led_off.wav");
    copy("led_on.wav");
    copy("w_on.wav");
    copy("w_off.wav");
    copy("mplayer");
    copy("record");
    copy("fire.wav");
    copy("fan_drv.ko");

    system("chmod 777 *");

    system("insmod light_drv.ko");
    system("insmod temp_dev.ko");
    system("insmod led_drv.ko");
    system("insmod beep_drv.ko");
    system("insmod fan_drv.ko");

    init_dht11();
//    init_led();
 //   light_init();
/*
    if(argc >= 3)
    {
        Rfid::Get()->serial = QString(argv[2]).toInt();
    }
    Rfid::Get()->start();
*/
    if(argc >= 2)
    {
        memset(SERVER_IP, 0, sizeof (SERVER_IP));
        memcpy(SERVER_IP, argv[1], strlen(argv[1]));
    }

    Cliect::get();


    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}
